home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / coreaids.zip / REPLACE.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  2KB  |  72 lines

  1. ;    DESC:    Replaces an occurence of a string with another       V1.00
  2. ;        string
  3. ;    IN:    *{RSTRNG} segment and
  4. ;        *{ROFF} offset of replacement string (must be same length)
  5. ;        *{DIR} direction of search (0:forward,1-FFFF:reverse)
  6. ;        *{SEG_VAL} segment and
  7. ;        *{OFFSET} offset of buffer to search
  8. ;        *{LENGTH} length of search string
  9. ;        *{SSTRNG} segment and
  10. ;        *{OSTRNG} offset of search string
  11. ;    OUT:    *{OSEG} segment and
  12. ;        *{OOFF} offset of replacement (both zero if not replaced)
  13. ;    SAMPLE:    Callm    REPLACE,<RSTRNG,ROFF,DIR,SEG_VAL,OFFSET,LENGTH,
  14. ;                SSTRNG,OSTRNG>,<OSEG,OOFF>
  15. ;    ####################################################################
  16.  
  17.     Extrn    PUSHALL:Near
  18.     Extrn    POPALL:Near
  19.     Extrn    SEARCH:Near
  20.     Extrn    MOVE_BYT:Near
  21.  
  22. REPLACEC    Segment
  23.     Assume    CS:REPLACEC
  24.     Public    REPLACE
  25.  
  26.     Include    CALLM.MAC
  27.                         ;notice.
  28.     DB    'REPLACE  - V1.00, Copyright 1987, CoreTechs   ',0DH,0AH
  29.  
  30. REPLACE    Proc    Near
  31.     Call    PUSHALL                ;save registers.
  32.  
  33.     Pop    AX
  34.     Pop    BX
  35.     Pop    CX                ;recover length of search
  36.     Push    CX                ;string and replace
  37.     Push    BX                ;parameters.
  38.     Push    AX
  39.  
  40.     Call    Search                ;perform search with arguments
  41.                         ;already on stack.
  42.  
  43.     Pop    AX                ;recover segment and
  44.     Pop    BP                ;offset of match.
  45.  
  46.     Cmp    AX,0                ;if both zero nothing found.
  47.     Jz    TST2
  48.     Jmp    CONT
  49.  
  50. TST2:    Cmp    BP,0
  51.     Jz    OUT2
  52.  
  53.  
  54. CONT:    Cld
  55.     Callm    MOVE_BYT,<AX,BP,CX>,        ;add additional parameters
  56.                         ;to call. input buffer address
  57.                         ;is already on stack.
  58.  
  59. OUT:    Push    BP                ;return address of replace.
  60.     Push    AX
  61.  
  62.     Call    POPALL                ;recover registers.
  63.     Ret
  64.  
  65. OUT2:    Pop    BX
  66.     Pop    BX
  67.     Jmp    OUT
  68.  
  69. REPLACE    Endp
  70. REPLACEC    Ends
  71.     End
  72.